//
//  JjMainViewController.swift
//  carHome
//
//  Created by Wu YJ on 16/2/24.
//  Copyright © 2016年 Wu YJ. All rights reserved.
//

import UIKit

class JjMainViewController: UITabBarController {

    override func viewDidLoad()
    {
        super.viewDidLoad()
        //推荐
        let recommendVC = JjRecommendTableViewController()
        addChildViewController(recommendVC, imageName: "item01")
        //论坛
        let forumVC = JjForumTableViewController()
        addChildViewController(forumVC, imageName: "item02")
        //找车
        let carVC = JjCarTableViewController()
        addChildViewController(carVC, imageName: "item03")
        //发现
        let findVC = JjFindTableViewController()
        addChildViewController(findVC, imageName: "item04")
        //我
        let meVC = JjMeTableViewController()
        addChildViewController(meVC, imageName: "item05")
    }
    
    
    /*
        自定义添加tabbar自控制器
        - parameter childController: 子控制器
        - parameter imageName: 图片的名称
    */
    private func addChildViewController(childController: UIViewController, imageName: String)
    {
        childController.tabBarItem.image = UIImage(named: imageName)
        
        //拼接高亮图片
        let highlightedImageName = imageName + "_selected";
        //让选中的图片使用原来的颜色，不要让系统渲染
        let highlightedImage = UIImage(named: highlightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        childController.tabBarItem.selectedImage = highlightedImage
        //让图片垂直居中
        let imageOffset: CGFloat = 5.0
        childController.tabBarItem.imageInsets = UIEdgeInsetsMake(imageOffset, 0, -imageOffset, 0)
        
        addChildViewController(UINavigationController(rootViewController: childController))
    }
}
